using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class MainPanel : MonoBehaviour
{
    [Header("UI组件")]
    public TextMeshProUGUI hookCounterText;
    public TextMeshProUGUI harpoonCounterText;
    public Button FinishPanle;
    public Button SetPanle;
    public Button DepthPanle;

    public TextMeshProUGUI LevelText;
    public TextMeshProUGUI DepthText;
    
    private void Start()
    {
        // 订阅库存变化事件
        InventoryManager.Instance.OnInventoryChanged += UpdateUI;
        // 初始更新
        UpdateUI();
        
        FinishPanle.onClick.AddListener(FinishPanel);
        SetPanle.onClick.AddListener(SetPanel);
        //DepthPanle.onClick.AddListener(Depth);
    }

    private void Depth()
    {
        LevelManager.Instance.CurrentDepth++;
        FishSpanwe.Instance.Dive();
        UpdateUI();
    }

    public void FinishPanel()
    {
        UILoader.Instance.ToggleUI("FinishPanel");
    }
    public void SetPanel()
    {
        UILoader.Instance.ToggleUI("SettingPanel");
    }

    private void UpdateUI()
    {
        hookCounterText.text = $"Fishhook: {InventoryManager.Instance.HookUses}";
        harpoonCounterText.text = $"Fishnet: {InventoryManager.Instance.HarpoonUses}";
        
        LevelText.text = $"Level: {LevelManager.Instance.CurrentLevel}";
        DepthText.text = $"Depth: {LevelManager.Instance.CurrentDepth}";
    }

    private void OnDestroy()
    {
        // 取消订阅防止内存泄漏
        if (InventoryManager.Instance != null)
        {
            InventoryManager.Instance.OnInventoryChanged -= UpdateUI;
        }
    }
}
